package com.hedl.practice.diyJava.array;

import com.hedl.practice.diyJava.array.utils.ArraySort;

import java.util.Arrays;

public class JavaAndArraySort {

    public static void main(String[] args) {

        int[] ns = {28,12,89,73,65,18,96,50,8,35};
        String[] ns1 = {"banana","apple","pear"};

        //打印出来
        System.out.println(Arrays.toString(ns));
        //System.out.println(Arrays.toString(ns1));

        //冒泡排序
        /*for (int i = 0; i < ns.length;i++){
            for (int j = 0;j<ns.length-i-1;j++){
                if (ns[j] > ns[j+1]){

                    int tmp = ns[j];
                    ns[j] = ns[j+1];
                    ns[j+1] = tmp;
                }
            }
        }
        System.out.println(Arrays.toString(ns));*/

        //java内置的排序方法
       /* Arrays.sort(ns);
        System.out.println(Arrays.toString(ns));*/

        /*Arrays.sort(ns1);
        System.out.println(Arrays.toString(ns1));*/

        //练习,使用冒泡降序排序
        /*for (int i = ns.length-1;i >= 0;i--){   //9
            for (int j = ns.length-1-i;j > 0;j--){
                //System.out.println(ns[j]);
                if (ns[j] > ns[j-1]){
                    int tmp = ns[j];
                    ns[j] = ns[j-1];
                    ns[j-1] = tmp;
                }
            }
        }
        System.out.println(Arrays.toString(ns));
        if (Arrays.toString(ns).equals("[96, 89, 73, 65, 50, 35, 28, 18, 12, 8]")){
            System.out.println("测试成功");
        }else {
            System.out.println("测试失败");
        }*/

        //封装成工具类
        ArraySort as = new ArraySort();
        System.out.println(as.OrdemInversa(ns));

        //简写上述练习
        /*if (as.OrdemInversa(ns).equals("[96, 89, 73, 65, 50, 35, 28, 18, 12, 8]")){
            System.out.println("测试成功");
        }else {
            System.out.println("测试失败");
        }*/

    }
}
